<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="抵店时间">
                            <a-range-picker @change="changeDateArrival" format="YYYY-MM-DD" style="width: 100%;" />
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="预离店时间">
                            <a-range-picker @change="changeDateDeparture" format="YYYY-MM-DD" style="width: 100%;" />
                        </a-form-item>
                    </a-col>

                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">重置</a-button>
                            <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                                {{ toggleSearchStatus ? '收起' : '展开' }}
                                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                            </a> -->
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
            <!-- <a-button type="primary" icon="download" @click="handleExportXls('登记单信息主表')">导出</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
                <a-button type="primary" icon="import">导入</a-button>
            </a-upload> -->
            <!-- 高级查询区域 -->
            <j-super-query :fieldList="superFieldList" ref="superQueryModal"
                @handleSuperQuery="handleSuperQuery"></j-super-query>
            <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
                <a-menu slot="overlay">
                    <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
            </a-dropdown> -->
            <a-button @click="searchQuery" icon="reload" style="float: right;">刷新数据</a-button>
        </div>

        <!-- table区域-begin -->
        <div class="yudingdan-table">
            <div class="ant-alert ant-alert-info">
                <!-- <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
                    selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a> -->
                <!-- <i class="anticon anticon-info-circle ant-alert-icon"></i> -->
                已选择
                <a style="font-weight: 600">
                    {{ selectedRowKeys.length }}
                </a>
                项
                <a style="margin-left: 24px" @click="onClearSelected" v-if="selectedRowKeys.length">
                    清空
                </a>
            </div>

            <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap" :scroll="{ x: true }"
                :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
                :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                @change="handleTableChange">

                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <!-- <template slot="imgSlot" slot-scope="text,record">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
                        style="max-width:80px;font-size: 12px;font-style: italic;" />
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                        下载
                    </a-button>
                </template> -->

                <span slot="action" slot-scope="text, record" style="display: flex; flex-direction: column;">
                    <a-space>
                        <a-button size="small" @click="handleFenFang(record)" style="border: 1px solid gray;"
                            :disabled="record.auditFlag !== '0'">
                            分配房间
                        </a-button>
                        <a-button size="small" @click="handleRenyuan(record)" style="border: 1px solid gray;"
                            :disabled="record.auditFlag !== '0'">
                            人员登记
                        </a-button>
                    </a-space>
                    <a-space style="margin-top: 5px;">
                        <a-button size="small" @click="handleDetail(record)" style="border: 1px solid gray;">
                            详情
                        </a-button>
                        <a-button size="small" @click="handleEdit(record)" style="border: 1px solid gray;"
                            :disabled="record.auditFlag !== '0'">
                            编辑
                        </a-button>
                        <a-button size="small" @click="handleDeleteCheck(record)" style="border: 1px solid gray;"
                            :disabled="record.auditFlag !== '0'">
                            删除
                        </a-button>
                    </a-space>
                    <!-- <a @click="handleEdit(record)">编辑</a>

                    <a-divider type="vertical" />
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                        <a-menu slot="overlay">
                            <a-menu-item>
                                <a @click="handleDetail(record)">详情</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown> -->
                </span>

            </a-table>
        </div>

        <CheckInModal ref="modalForm" @ok="modalFormOk" />
        <CheckInBaseModal ref="baseModal" @closeModal="loadData()">
            <component :is="checkModal" :dingdan="openModel" />
        </CheckInBaseModal>
    </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CheckInModal from './modules/CheckInModal'
import '@/assets/less/TableExpand.less'
import CheckInBaseModal from './CheckInBaseModal'
import CheckInFangJianList from './FangJian/CheckInFangJianList'
import CheckInRenYuanList from './RenYuan/CheckInRenYuanList'

export default {
    name: "CheckInList",
    mixins: [JeecgListMixin],
    components: {
        CheckInModal,
        CheckInBaseModal,
        CheckInFangJianList,
        CheckInRenYuanList
    },
    data() {
        return {
            description: '登记单信息主表管理页面',
            openModel: {},
            checkModal: null,
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '登记编码',
                    align: "center",
                    dataIndex: 'roomRegisterCode'
                },


                {
                    title: '登记类型',
                    align: "center",
                    dataIndex: 'registerType_dictText'
                },
                {
                    title: '团体名称',
                    align: "center",
                    dataIndex: 'groupName'
                },
                {
                    title: '账户类型',
                    align: "center",
                    dataIndex: 'accountType_dictText'
                },
                {
                    title: '最早来期',
                    align: "center",
                    dataIndex: 'dateArrival'
                },
                {
                    title: '最晚离期',
                    align: "center",
                    dataIndex: 'dateDeparture'
                },
                {
                    title: '房间分配',
                    align: "center",
                    dataIndex: 'roomFpDesc',
                    scopedSlots: { customRender: 'htmlSlot' }
                },
                {
                    title: '余额',
                    align: "center",
                    dataIndex: 'amount'
                },
                {
                    title: '预订单号',
                    align: "center",
                    dataIndex: 'bookCode'
                },
                {
                    title: '状态',
                    align: "center",
                    dataIndex: 'registerStatus_dictText'
                },
                {
                    title: '夜审标记',
                    align: "center",
                    dataIndex: 'auditFlag_dictText'
                },
            ],
            url: {
                list: "/room/roomRegisterInfo/list",
                delete: "/room/roomRegisterInfo/delete",
                deleteBatch: "/room/roomRegisterInfo/deleteBatch",
                exportXlsUrl: "/room/roomRegisterInfo/exportXls",
                importExcelUrl: "room/roomRegisterInfo/importExcel",

            },
            dictOptions: {},
            superFieldList: [],
        }
    },
    created() {
        this.getSuperFieldList();
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        }
    },
    methods: {
        initDictConfig() {
        },
        changeDateArrival(dates, dateStrings) {
            this.queryParam.dateArrival_begin = dateStrings[0]
            this.queryParam.dateArrival_end = dateStrings[1]
        },
        changeDateDeparture(dates, dateStrings) {
            this.queryParam.dateDeparture_begin = dateStrings[0]
            this.queryParam.dateDeparture_end = dateStrings[1]
        },
        getSuperFieldList() {
            let fieldList = [];
            fieldList.push({ type: 'string', value: 'roomRegisterCode', text: '登记编码', dictCode: '' })
            fieldList.push({ type: 'string', value: 'registerType', text: '登记类型', dictCode: '' })
            fieldList.push({ type: 'string', value: 'groupName', text: '团体名称', dictCode: '' })
            fieldList.push({ type: 'string', value: 'accountType', text: '账户类型', dictCode: '' })
            fieldList.push({ type: 'string', value: 'dateArrival', text: '最早来期', dictCode: '' })
            fieldList.push({ type: 'string', value: 'dateDeparture', text: '最晚离期', dictCode: '' })
            fieldList.push({ type: 'int', value: 'dateNum', text: '房晚数', dictCode: '' })
            fieldList.push({ type: 'string', value: 'bookCode', text: '预订单号', dictCode: '' })
            this.superFieldList = fieldList
        },
        handleFenFang(record) {
            this.openModel = record
            this.checkModal = CheckInFangJianList
            this.$refs.baseModal.title = '入住分配房间'
            this.$refs.baseModal.show(record)
        },
        handleRenyuan(record) {
            this.openModel = record
            this.checkModal = CheckInRenYuanList
            this.$refs.baseModal.title = '入住人员登记'
            this.$refs.baseModal.show(record)
        },
        handleDeleteCheck(record) {
            const that = this
            this.$confirm({
                title: '确定删除吗?',
                content: '确定删除这条登记单吗？登记单号：' + record.roomRegisterCode,
                onCancel() { },
                onOk() {
                    that.handleDelete(record.id)
                },
            });
        }
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.yudingdan-table ::v-deep .ant-table-tbody td {
    border-bottom: 1px solid rgba(0, 0, 0, 0.25) !important;
}

.yudingdan-table ::v-deep .ant-table-thead th {
    border-bottom: 1px solid rgba(0, 0, 0, 0.25) !important;
}
</style>